package com.twu.biblioteca;

import com.twu.biblioteca.command.CheckoutCommand;
import com.twu.biblioteca.command.Command;
import com.twu.biblioteca.command.ListBooksCommand;
import com.twu.biblioteca.command.ReturnBookCommand;

import java.io.*;
import java.util.Map;
import java.util.TreeMap;


public class Main {

    public static void main(String args[]) throws IOException {

        PrintStream printStream = System.out;
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        Library library = new Library(printStream, new StringJoiner(), initBookList());

        Map<String, Command> commandMap = new TreeMap<String, Command>();
        commandMap.put("1", new ListBooksCommand(library));
        commandMap.put("2", new CheckoutCommand(printStream, reader, library));
        commandMap.put("3", new ReturnBookCommand(printStream, reader, library));

        Menu menu = new Menu(printStream, reader, commandMap);
        BibliotecaController controller = new BibliotecaController(printStream, library, menu);

        controller.start();


    }
    private static Map<String, Book> initBookList() {
        Map<String, Book> books = new TreeMap<String, Book>();
        books.put("1", new Book("Head First Java", "Kathy", "2007"));
        books.put("2", new Book("Spring in action", "Craig", "2011"));
        books.put("3", new Book("Kan Jian", "Chai Jing", "2010"));
        return books;
    }


}
